package com.sina.weibo.sdk.web;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.sina.weibo.sdk.auth.BaseSsoHandler;
import com.sina.weibo.sdk.web.view.LoadingBar;
import o.fnm;
import o.fnn;
import o.fnq;
import o.fns;
import o.fnv;
import o.fnw;
import o.fnx;
import o.fny;
import o.fnz;
import o.foa;
import o.fob;
import o.foc;
import o.foc.d;
import o.fod;

public class WeiboSdkWebActivity extends Activity implements fnv {
    private TextView ʻ;
    private LinearLayout ʼ;
    private fny ʽ;
    private TextView ˊ;
    private WebView ˋ;
    private Button ˎ;
    private TextView ˏ;
    private LoadingBar ॱ;
    private foc ॱॱ;
    private int ᐝ = 0;

    class b extends WebChromeClient {
        final /* synthetic */ WeiboSdkWebActivity ॱ;

        private b(WeiboSdkWebActivity weiboSdkWebActivity) {
            this.ॱ = weiboSdkWebActivity;
        }

        public void onProgressChanged(WebView webView, int i) {
            super.onProgressChanged(webView, i);
            this.ॱ.ॱ.ˏ(i);
            if (i == 100) {
                this.ॱ.ॱ.setVisibility(4);
            } else {
                this.ॱ.ॱ.setVisibility(0);
            }
        }

        public void onReceivedTitle(WebView webView, String str) {
            super.onReceivedTitle(webView, str);
            if (TextUtils.isEmpty(this.ॱ.ॱॱ.ˋ().ॱ())) {
                this.ॱ.ˏ.setText(str);
            }
        }
    }

    protected void onCreate(Bundle bundle) {
        fnm.ॱ("Share", "startWebActivity");
        requestWindowFeature(1);
        super.onCreate(bundle);
        setContentView(ˎ());
        ˊ();
    }

    private void ˊ() {
        fnm.ॱ("Share", "WebActivity.initLoad().start");
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }
        int i = extras.getInt("type", -1);
        if (i == -1) {
            finish();
            return;
        }
        switch (i) {
            case 0:
                this.ॱॱ = new fod();
                this.ʽ = new fnx(this, this.ॱॱ);
                break;
            case 1:
                this.ॱॱ = new fnz(this);
                this.ʽ = new foa(this, this, this.ॱॱ);
                break;
            case 2:
                this.ॱॱ = new fob();
                this.ʽ = new fnw(this, this, this.ॱॱ);
                break;
        }
        this.ˋ.setWebViewClient(this.ʽ);
        this.ॱॱ.ˏ(extras);
        ˋ();
        if (this.ॱॱ.ॱ()) {
            this.ॱॱ.ˊ(new d(this) {
                final /* synthetic */ WeiboSdkWebActivity ॱ;

                {
                    this.ॱ = r1;
                }

                public void ॱ(String str) {
                    fnm.ॱ("Share", "WebActivity.sharePic.onComplete()");
                    if (this.ॱ.ॱ(this.ॱ.ॱॱ.ˊ())) {
                        this.ॱ.ˋ.loadUrl(this.ॱ.ॱॱ.ˊ());
                    }
                }

                public void ˎ(String str) {
                    fnm.ॱ("Share", "WebActivity.sharePic.onException()");
                    this.ॱ.ʽ.ˊ(this.ॱ, "pic upload error");
                    this.ॱ.finish();
                }
            });
        } else {
            String ˊ = this.ॱॱ.ˊ();
            if (ॱ(ˊ)) {
                this.ˋ.loadUrl(ˊ);
            }
        }
        fnm.ॱ("Share", "WebActivity.initLoad().end");
    }

    private boolean ॱ(String str) {
        if (TextUtils.isEmpty(str) || (!str.startsWith("https://service.weibo.com/share/mobilesdk.php") && !str.startsWith(BaseSsoHandler.OAUTH2_BASE_URL))) {
            return false;
        }
        return true;
    }

    private View ˎ() {
        View relativeLayout = new RelativeLayout(this);
        relativeLayout.setBackgroundColor(-1);
        View relativeLayout2 = new RelativeLayout(this);
        this.ˊ = new TextView(this);
        this.ˊ.setTextSize(17.0f);
        this.ˊ.setTextColor(fnn.ॱ(-32256, 1728020992));
        this.ˊ.setText(fnn.ˊ(this, "Close", "关闭", "关闭"));
        this.ˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ WeiboSdkWebActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                this.ॱ.ʽ.ˏ();
                this.ॱ.ˏ();
            }
        });
        this.ˏ = new TextView(this);
        this.ˏ.setTextSize(18.0f);
        this.ˏ.setTextColor(-11382190);
        LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
        LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams.addRule(15);
        this.ˊ.setPadding(fns.ॱ(10, this), 0, fns.ॱ(10, this), 0);
        layoutParams2.addRule(13);
        relativeLayout2.addView(this.ˊ, layoutParams);
        relativeLayout2.addView(this.ˏ, layoutParams2);
        relativeLayout.addView(relativeLayout2, new RelativeLayout.LayoutParams(-1, fns.ॱ(55, this)));
        this.ˋ = new WebView(getApplicationContext());
        this.ˋ.getSettings().setSavePassword(false);
        this.ˋ.getSettings().setAllowFileAccess(false);
        this.ˋ.getSettings().setAllowContentAccess(false);
        LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-1, -1);
        layoutParams3.topMargin = fns.ॱ(55, this);
        relativeLayout.addView(this.ˋ, layoutParams3);
        this.ॱ = new LoadingBar(this);
        layoutParams3 = new RelativeLayout.LayoutParams(-1, fns.ॱ(3, this));
        layoutParams3.topMargin = fns.ॱ(55, this);
        relativeLayout.addView(this.ॱ, layoutParams3);
        relativeLayout2 = new View(this);
        relativeLayout2.setBackgroundResource(getResources().getIdentifier("weibosdk_common_shadow_top", "drawable", getPackageName()));
        layoutParams = new RelativeLayout.LayoutParams(-1, fns.ॱ(3, this));
        layoutParams.topMargin = fns.ॱ(55, this);
        relativeLayout.addView(relativeLayout2, layoutParams);
        this.ʼ = new LinearLayout(this);
        this.ʼ.setOrientation(1);
        relativeLayout2 = new ImageView(this);
        relativeLayout2.setImageResource(getResources().getIdentifier("weibosdk_empty_failed", "drawable", getPackageName()));
        this.ʼ.addView(relativeLayout2);
        this.ʻ = new TextView(this);
        this.ʻ.setTextSize(14.0f);
        this.ʻ.setTextColor(-4342339);
        layoutParams3 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams3.topMargin = fns.ॱ(18, this);
        layoutParams3.bottomMargin = fns.ॱ(20, this);
        this.ʼ.addView(this.ʻ, layoutParams3);
        this.ˎ = new Button(this);
        this.ˎ.setTextSize(16.0f);
        this.ˎ.setTextColor(-8882056);
        layoutParams3 = new LinearLayout.LayoutParams(fns.ॱ(142, this), fns.ॱ(46, this));
        layoutParams3.gravity = 17;
        this.ʼ.addView(this.ˎ, layoutParams3);
        this.ˎ.setBackgroundResource(getResources().getIdentifier("retry_btn_selector", "drawable", getPackageName()));
        layoutParams3 = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams3.addRule(13);
        relativeLayout.addView(this.ʼ, layoutParams3);
        this.ʼ.setVisibility(8);
        this.ˋ.setWebChromeClient(new b());
        this.ˎ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ WeiboSdkWebActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                this.ˊ.ᐝ = 0;
                this.ˊ.ʻ();
                this.ˊ.ˋ.reload();
            }
        });
        this.ʻ.setText(fnn.ˊ(this, "A network error occurs, please tap the button to reload", "网络出错啦，请点击按钮重新加载", "網路出錯啦，請點擊按鈕重新載入"));
        this.ˎ.setText(fnn.ˊ(this, "channel_data_error", "重新加载", "重新載入"));
        return relativeLayout;
    }

    @SuppressLint({"SetJavaScriptEnabled"})
    private void ˋ() {
        if (!TextUtils.isEmpty(this.ॱॱ.ˋ().ॱ())) {
            this.ˏ.setText(this.ॱॱ.ˋ().ॱ());
        }
        this.ˋ.getSettings().setJavaScriptEnabled(true);
        this.ˋ.getSettings().setSavePassword(false);
        this.ˋ.getSettings().setUserAgentString(fnq.ॱ(this, this.ॱॱ.ˋ().ˏ().getAppKey()));
        this.ˋ.requestFocus();
        this.ˋ.setScrollBarStyle(0);
        ˎ(this.ˋ, "searchBoxJavaBridge_");
        ˎ(this.ˋ, "accessibility");
        ˎ(this.ˋ, "accessibilityTraversal");
        if (VERSION.SDK_INT >= 21) {
            this.ˋ.getSettings().setMixedContentMode(2);
        }
    }

    public static void ˎ(WebView webView, String str) {
        try {
            WebView.class.getDeclaredMethod("removeJavascriptInterface", new Class[]{String.class}).invoke(webView, new Object[]{str});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void ˏ() {
        finish();
    }

    private void ʽ() {
        this.ʼ.setVisibility(0);
        this.ˋ.setVisibility(8);
    }

    private void ʻ() {
        this.ʼ.setVisibility(8);
        this.ˋ.setVisibility(0);
    }

    public void ˊ(WebView webView, String str, Bitmap bitmap) {
    }

    public void ˊ(WebView webView, String str) {
        if (this.ᐝ == -1) {
            ʽ();
        } else {
            ʻ();
        }
    }

    public boolean ˏ(WebView webView, String str) {
        return false;
    }

    public void ॱ(WebView webView, int i, String str, String str2) {
        Object url = webView.getUrl();
        try {
            if (!TextUtils.isEmpty(url) && !TextUtils.isEmpty(str2)) {
                Uri parse = Uri.parse(url);
                Uri parse2 = Uri.parse(str2);
                if (parse.getHost().equals(parse2.getHost()) && parse.getScheme().equals(parse2.getScheme())) {
                    this.ᐝ = -1;
                }
            }
        } catch (Exception e) {
        }
    }

    public void ॱ(WebView webView, final SslErrorHandler sslErrorHandler, SslError sslError) {
        Builder builder = new Builder(this);
        builder.setTitle("警告");
        builder.setMessage("你访问的连接可能存在隐患，是否继续访问");
        builder.setPositiveButton("继续", new DialogInterface.OnClickListener(this) {
            final /* synthetic */ WeiboSdkWebActivity ॱ;

            public void onClick(DialogInterface dialogInterface, int i) {
                sslErrorHandler.proceed();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener(this) {
            final /* synthetic */ WeiboSdkWebActivity ˊ;

            public void onClick(DialogInterface dialogInterface, int i) {
                sslErrorHandler.cancel();
            }
        });
        builder.create().show();
    }

    public void ॱ() {
        finish();
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i == 4) {
            if (this.ʽ.ॱ()) {
                return true;
            }
            if (this.ˋ.canGoBack()) {
                this.ˋ.goBack();
                return true;
            }
        }
        return super.onKeyDown(i, keyEvent);
    }
}
